﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Security;
namespace JTicket.BLL
{
    public class RoleBase : Page
    {
        #region PageInit
        /// <summary>
        /// 判断账号权限
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            var a = BLL.M_OperRight.GetRoleList(User.Identity.Name);
            bool result = false;
            if (GetBusiness().Count > 0)
            {
                foreach (var str in GetBusiness())
                {
                    if (a.Contains(str))
                    {
                        result = true;
                        continue;
                    }
                }
                if (result)
                    base.OnLoad(e);
                else
                    throw new Exception("权限过界");
            }
            else
                throw new Exception("权限不够");
        }
        /// <summary>
        /// 获取权限代码
        /// </summary>
        /// <returns></returns>
        private List<string> GetBusiness()
        {
            //访问的页面
            string rawurl = Context.Request.RawUrl;
            string suburl = string.Format("{0}{1}",
                rawurl.ToString().Substring(1, rawurl.IndexOf('.')), "aspx");
            return BLL.C_CodeNote.SelectCodeValue(suburl);
        }
        #endregion
    
    }
}